#include "cutil.h"
#include <string.h>



uint8_t *data_find_char(const uint8_t *pdata, uint16_t size, char c)
{
    uint8_t *ptr;
    for (ptr = (uint8_t*)pdata; ptr < pdata + size; ptr++)
    {
        if (*ptr == c)
        {
            return ptr;
        }
    }
    return 0;
}

/**
 * @brief 寻找子数据串
 * @param pdata 数据指针
 * @param size 数据长度
 * @param subdata 子数据指针
 * @param subdatasize 子串长度 
 * @retval uint8_t* 
 */
uint8_t *data_find_sub(const uint8_t *pdata, uint8_t size, const uint8_t *subdata, uint8_t subdatasize)
{
    int i, j = 0;
    // 搜索子数据串 "abcdeefght" "de"
    for (i = 0; i < size; i++)
    {
        if (pdata[i] == subdata[j])
        {
            j++;
            if (j == subdatasize)
            {
                return (uint8_t*)(pdata + i - subdatasize + 1);
            }
        }
        else
        {
            if (size - i < subdatasize) break;
            i -= j;
            j = 0;
        }
    }
	return NULL;
}


